home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 20 / Cream of the Crop 20 (Terry Blount) (1996).iso / program / vol15n11.zip / TBWIZ.ZIP / SAVEFORM.FRM < prev    next >
Text File  |  1996-02-24  |  9KB  |  321 lines

  1. VERSION 4.00
  2. Begin VB.Form tbSaveForm 
  3.    BorderStyle     =   3  'Fixed Dialog
  4.    Caption         =   "Save Toolbar"
  5.    ClientHeight    =   1590
  6.    ClientLeft      =   2850
  7.    ClientTop       =   3315
  8.    ClientWidth     =   4515
  9.    ControlBox      =   0   'False
  10.    Height          =   1995
  11.    Left            =   2790
  12.    LinkTopic       =   "Form1"
  13.    MaxButton       =   0   'False
  14.    MinButton       =   0   'False
  15.    ScaleHeight     =   1590
  16.    ScaleWidth      =   4515
  17.    ShowInTaskbar   =   0   'False
  18.    Top             =   2970
  19.    Width           =   4635
  20.    Begin VB.CommandButton Command2 
  21.       Caption         =   "Cancel"
  22.       Height          =   325
  23.       Left            =   3480
  24.       TabIndex        =   5
  25.       Top             =   720
  26.       Width           =   975
  27.    End
  28.    Begin VB.CommandButton Command1 
  29.       Caption         =   "&Save"
  30.       Height          =   325
  31.       Left            =   3480
  32.       TabIndex        =   4
  33.       Top             =   240
  34.       Width           =   975
  35.    End
  36.    Begin VB.Frame Frame1 
  37.       Caption         =   "Select Toolbar:"
  38.       Height          =   1335
  39.       Left            =   120
  40.       TabIndex        =   0
  41.       Top             =   120
  42.       Width           =   3135
  43.       Begin VB.ComboBox Combo1 
  44.          Height          =   315
  45.          Index           =   0
  46.          Left            =   1065
  47.          TabIndex        =   2
  48.          Text            =   "Combo1"
  49.          Top             =   480
  50.          Width           =   1815
  51.       End
  52.       Begin VB.Label Label2 
  53.          BorderStyle     =   1  'Fixed Single
  54.          Height          =   275
  55.          Left            =   1080
  56.          TabIndex        =   6
  57.          Top             =   840
  58.          Visible         =   0   'False
  59.          Width           =   1815
  60.       End
  61.       Begin VB.Label Label1 
  62.          AutoSize        =   -1  'True
  63.          Caption         =   "ImageList:"
  64.          Height          =   195
  65.          Index           =   1
  66.          Left            =   240
  67.          TabIndex        =   3
  68.          Top             =   860
  69.          Visible         =   0   'False
  70.          Width           =   720
  71.       End
  72.       Begin VB.Label Label1 
  73.          AutoSize        =   -1  'True
  74.          Caption         =   "Toolbar:"
  75.          Height          =   195
  76.          Index           =   0
  77.          Left            =   360
  78.          TabIndex        =   1
  79.          Top             =   510
  80.          Width           =   585
  81.       End
  82.    End
  83.    Begin MSComDlg.CommonDialog CommonDialog1 
  84.       Left            =   3720
  85.       Top             =   1080
  86.       _Version        =   65536
  87.       _ExtentX        =   847
  88.       _ExtentY        =   847
  89.       _StockProps     =   0
  90.       CancelError     =   -1  'True
  91.       DefaultExt      =   "*.tbr"
  92.       DialogTitle     =   "Save Toolbar"
  93.       Filter          =   "*.tbr | Toolbars"
  94.    End
  95. End
  96. Attribute VB_Name = "tbSaveForm"
  97. Attribute VB_Creatable = False
  98. Attribute VB_Exposed = False
  99. Option Explicit
  100. DefInt A-Z
  101.  
  102. Function GetImageListName$()
  103. GetImageListName$ = ""
  104. '___setup vars
  105. Dim CurrFormName$, CurrFormFiles$(1)
  106. Dim i%, ii%
  107. '___get form file names
  108. With gobjIDEAppInst.ActiveProject
  109.     CurrFormName$ = .ActiveForm.Properties.Item("Name")
  110.     With .Components
  111.         For i% = 0 To .Count - 1
  112.             If .Item(i%).Name = CurrFormName$ Then CurrFormFiles$(0) = .Item(i%).FileNames(0)
  113.         Next
  114.     End With
  115. End With
  116. If CurrFormFiles$(0) = "" Or (Len(CurrFormFiles$(0)) = 0) Then
  117.     Alert "Save form file first!"
  118.     Exit Function
  119. End If
  120.  
  121. '___more vars...
  122. Dim Source$
  123. Dim linetest$
  124. Dim tbTest$
  125. Source$ = CurrFormFiles$(0)
  126. Const icTest$ = "ImageList"
  127. tbTest$ = "Toolbar " & Combo1(0)
  128. '___get imagelist name
  129. Open Source$ For Input As #2
  130.     Do While Not EOF(2)
  131.         Line Input #2, linetest$
  132.         If InStr(linetest$, tbTest$) > 0 Then
  133.            '___we found the toolbar
  134.             Do
  135.               Line Input #2, linetest$
  136.               linetest$ = Trim$(linetest$)
  137.               If Left$(linetest$, 9) = icTest$ Then
  138.               '___we found the imagelist
  139.                ii% = InStr(linetest$, Chr$(34))
  140.                If ii% > 0 Then
  141.                     linetest$ = Mid$(linetest$, ii% + 1)
  142.                     ii% = InStr(linetest$, Chr$(34))
  143.                     GetImageListName$ = Left$(linetest$, ii% - 1)
  144.                 End If
  145.                 Close #2
  146.                 Exit Function
  147.             End If
  148.             Loop
  149.          End If
  150.      Loop
  151. Close #2
  152. End Function
  153.  
  154.  
  155. Function SaveTB() As Integer
  156. '___setup vars
  157. Dim ProjectFilename$, ProjectDirty As Boolean
  158. Dim CurrFormName$, CurrFormFiles$(1)
  159. Dim i%, ii%
  160. Dim success As Boolean
  161. '___get form file names
  162. With gobjIDEAppInst.ActiveProject
  163.     CurrFormName$ = .ActiveForm.Properties.Item("Name")
  164.     With .Components
  165.         For i% = 0 To .Count - 1
  166.             If .Item(i%).Name = CurrFormName$ Then
  167.                 CurrFormFiles$(0) = .Item(i%).FileNames(0)
  168.                 CurrFormFiles$(1) = .Item(i%).FileNames(1)
  169.             End If
  170.         Next
  171.     End With
  172. End With
  173. If CurrFormFiles$(0) = "" Or (Len(CurrFormFiles$(0)) = 0) Then
  174.     Alert "Save form file first!"
  175.     SaveTB = -1
  176.     Exit Function
  177. End If
  178.  
  179. '___get name of target TBR file from user
  180. On Error Resume Next
  181. CommonDialog1.ShowSave
  182. If Err = cdlCancel Then SaveTB = 0: Exit Function
  183. On Error GoTo 0
  184. gfnameTBFile = CommonDialog1.FileName
  185. Screen.MousePointer = HOURGLASS
  186.  
  187. '___more vars...
  188. Dim Source$
  189. Source$ = CurrFormFiles$(0)
  190. Dim linetest$
  191. Dim Targ$
  192. Dim tbEvent$
  193. Dim icTest$, tbTest$
  194. Dim Terminator$
  195. 'icTest$ = "ImageList " & Label2 '& Combo1(1)
  196. Const imagelistID = "ImageList"
  197. tbTest$ = "Toolbar " & Combo1(0)
  198. tbEvent$ = Combo1(0) & "_"
  199. Targ$ = ExtractFilePath$(gfnameTBFile) + ExtractFileRoot(gfnameTBFile) + ".tbr"
  200. Terminator$ = "End"
  201.  
  202. '___first get imagelist name
  203. Open Source$ For Input As #2
  204.     Do While Not EOF(2)
  205.         Line Input #2, linetest$
  206.         If InStr(linetest$, tbTest$) > 0 Then
  207.            '___we found the toolbar
  208.             Do
  209.               Line Input #2, linetest$
  210.               linetest$ = Trim$(linetest$)
  211.               If Left$(linetest$, 9) = imagelistID Then
  212.               '___we found the imagelist
  213.                ii% = InStr(linetest$, Chr$(34))
  214.                If ii% > 0 Then
  215.                     linetest$ = Mid$(linetest$, ii% + 1)
  216.                     ii% = InStr(linetest$, Chr$(34))
  217.                     icTest$ = "ImageList " & Left$(linetest$, ii% - 1)
  218.                 End If
  219.                 Exit Do
  220.             End If
  221.             Loop
  222.             If Len(icTest$) Then Exit Do
  223.          End If
  224.   Loop
  225. Close #2
  226.  
  227.  
  228.  
  229. '___now copy controls from frm to tbr file
  230. Open Targ$ For Output As #1
  231. Open Source$ For Input As #2
  232.     Do While Not EOF(2)
  233.         Line Input #2, linetest$
  234.         If (InStr(linetest$, icTest$) > 0) Or (InStr(linetest$, tbTest$) > 0) Then
  235.            '___we found the toolbar or imagelist
  236.             Print #1, linetest$
  237.             Do
  238.               Line Input #2, linetest$
  239.               Print #1, linetest$
  240.             Loop Until Trim$(linetest$) = Terminator$
  241.          End If
  242.      Loop
  243. Close #2
  244. '___now copy the toolbar's event handlers
  245. Terminator$ = "End Sub"
  246. Print #1, "TB_EVENTS"
  247. Open Source$ For Input As #2
  248.     Do While Not EOF(2)
  249.         Line Input #2, linetest$
  250.         If InStr(linetest$, tbEvent$) > 0 Then
  251.             '___we found a toolbar event handler
  252.             Print #1, linetest$
  253.             Do
  254.               Line Input #2, linetest$
  255.               Print #1, linetest$
  256.             Loop Until Trim$(linetest$) = Terminator$
  257.         End If
  258.     Loop
  259. Close #2
  260. Close #1
  261.  
  262. '___copy frx file
  263. Targ$ = ExtractFilePath$(gfnameTBFile) + ExtractFileRoot(gfnameTBFile) + ".frx"
  264. FileCopy ExtractFilePath$(Source$) + ExtractFileRoot(Source$) + ".frx", Targ$
  265. SaveTB = 1
  266. End Function
  267.  
  268. Private Sub Combo1_Click(Index As Integer)
  269. 'Label2 = GetImageListName$()
  270. End Sub
  271.  
  272.  
  273. Private Sub Command1_Click()
  274. Select Case SaveTB()
  275. Case -1 'form hasn't been saved